//
//  ISTransitionController.m
//  iSocket
//
//  Created by lhj on 1/28/16.
//  Copyright © 2016 boer. All rights reserved.
//

#import "IMTransitionController.h"
#import "IMTabBarController.h"

@interface IMTransitionController ()

@property (weak, nonatomic) UIImageView *imageView;
@property (strong, nonatomic) NSTimer *timer;

@end

@implementation IMTransitionController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    NSString *imageName;
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    if (height == 736) {
        imageName = @"default_6p";
    }else if (height == 667){
        imageName = @"default_6";
    }else if (height == 568){
        imageName = @"default_l";
    }else if (height == 480){
        imageName = @"default";
    }
    imageView.image = [UIImage imageNamed:imageName];
    self.imageView = imageView;
    [self.view addSubview:imageView];
    
    // 登录
//    BOOL isAutoLogin = ![[[NSUserDefaults standardUserDefaults] objectForKey:ISNotAutoLogin] isEqualToString:@"YES"];;
//    // 自动登录
//    if (isAutoLogin) {
//        // 验证自动在线是否过期
//        WeakSelf
//        
//        [[ISNetManager sharedManager] verifyAccountFinished:^(id response, NSError *error) {
//            
//            if (!error) {
//                ISPersonalInfo *user = [ISPersonalInfo mj_objectWithKeyValues:response[@"user"]];
//                if (user.token && user.nickName && user.phoneNumber) {
//                    // 存入沙盒
//                    [[NSUserDefaults standardUserDefaults] setObject:user.phoneNumber forKey:ISPhoneNumber];
//                    [[NSUserDefaults standardUserDefaults] setObject:user.nickName forKey:ISNickName];
//                    [[NSUserDefaults standardUserDefaults] setObject:user.token forKey:ISUserToken];
//                }
//                [weakSelf toMainViewController:user];
//            }else{
//                [weakSelf toLoginViewControllerWithErrorMessage:[ISErrorMessage errorMessageWithCode:error.code]];
//            }
//        }];
//
//    // 不自动登录
//    }else{
//        [self toLoginViewControllerWithErrorMessage:nil];
//    }
    [self toMainViewController];
}

- (void)jump{
//    [[ISNetManager sharedManager].tasks makeObjectsPerformSelector:@selector(cancel)];
//    [self toLoginViewControllerWithErrorMessage:@"网络出错了, 请手动登录!"];
}

- (void)toLoginViewControllerWithErrorMessage:(NSString *)message{
    // 登录界面
//    ISLoginController *loginVc = [[ISLoginController alloc] init];
//    loginVc.errorMessage = message;
//    ISBaseNavigationController *navc = [[ISBaseNavigationController alloc] initWithRootViewController:loginVc];
//    
//    [UIView transitionFromView:[UIApplication sharedApplication].keyWindow.rootViewController.view toView:navc.view duration:1 options:UIViewAnimationOptionTransitionNone completion:^(BOOL finished)
//     {
//         [UIApplication sharedApplication].keyWindow.rootViewController = navc;
//     }];
}

- (void)toMainViewController{
//     跳转首页
//     此处包装导航控制器是为了统一 （登录跳转的时候会包装）
    IMTabBarController *tabbar = [[IMTabBarController alloc] init];
    
    [UIView transitionFromView:[UIApplication sharedApplication].keyWindow.rootViewController.view toView:tabbar.view duration:0.2 options:UIViewAnimationOptionTransitionNone completion:^(BOOL finished)
     {
         [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
     }];
}

@end
